<?php
require(__META_CONTROLS_GEN__ . '/SeasonMetaControlGen.class.php');

/**
 * This is a MetaControl customizable subclass, providing a QForm or QPanel access to event handlers
 * and QControls to perform the Create, Edit, and Delete functionality of the
 * Season class.  This code-generated class extends from
 * the generated MetaControl class, which contains all the basic elements to help a QPanel or QForm
 * display an HTML form that can manipulate a single Season object.
 *
 * To take advantage of some (or all) of these control objects, you
 * must create a new QForm or QPanel which instantiates a SeasonMetaControl
 * class.
 *
 * This file is intended to be modified.  Subsequent code regenerations will NOT modify
 * or overwrite this file.
 *
 * @package My QCubed Application
 * @subpackage MetaControls
 */
class SeasonMetaControl extends SeasonMetaControlGen {
    // Initialize fields with default values from database definition
    /*
		public function __construct($objParentObject, Season $objSeason) {
			parent::__construct($objParentObject,$objSeason);
			if ( !$this->blnEditMode ){
				$this->objSeason->Initialize();
			}
		}
    */
    protected $lstSeason;
    public function lstSeason_Create($strControlId = null) {
        $this->lstSeason = new QListBox($this->objParentObject, $strControlId);
        $this->lstSeason->Name = QApplication::Translate('Season');
        $objSeasonArray = Season::LoadAll();

        if ($objSeasonArray) foreach ($objSeasonArray as $objSeason) {
                $objListItem = new QListItem($objSeason->Name, $objSeason->Id);

                if ( $objSeason->Active )
                    $objListItem->Selected = true;
                $this->lstSeason->AddItem($objListItem);
            }
         else{
             $objListItem = new QListItem("No Season(s) Set", null);
             $this->lstSeason->AddItem($objListItem);
         }

        return $this->lstSeason;
    }

    public function calDateFrom_Create($strControlId = null) {
        $this->calDateFrom = new QCalendarPopup($this->objParentObject, $strControlId);
        $this->calDateFrom->Name = QApplication::Translate('Date From');
        $this->calDateFrom->DateTime = $this->objSeason->DateFrom;
        $this->calDateFrom->Required = true;
        return $this->calDateFrom;
    }
    public function calDateTo_Create($strControlId = null) {
        $this->calDateTo = new QCalendarPopup($this->objParentObject, $strControlId);
        $this->calDateTo->Name = QApplication::Translate('Date To');
        $this->calDateTo->DateTime = $this->objSeason->DateTo;
        $this->calDateTo->Required = true;
        return $this->calDateTo;
    }

    public function SaveSeason() {
        try {
            // Update any fields for controls that have been created
            if ($this->txtName) $this->objSeason->Name = $this->txtName->Text;

            if ($this->calDateFrom) $this->objSeason->DateFrom = $this->calDateFrom->DateTime;
            if ($this->calDateTo) $this->objSeason->DateTo = $this->calDateTo->DateTime;
            if ($this->chkActive) $this->objSeason->Active = $this->chkActive->Checked;

            // Update any UniqueReverseReferences (if any) for controls that have been created for it

            // Save the Season object
            $this->objSeason->Save();

            // Finally, update any ManyToManyReferences (if any)
        } catch (QCallerException $objExc) {
            $objExc->IncrementOffset();
            throw $objExc;
        }
    }
}
?>